<?php

/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

function userlist() {
    if (cookie('account')) {
        $where['id'] = cookie('id');
        $userinfo = M('user')->where($where)->find();
        return $userinfo;
    }
}

/**
 * 系统邮件发送函数
 * @param string $to    接收邮件者邮箱
 * @param string $name  接收邮件者名称
 * @param string $subject 邮件主题 
 * @param string $body    邮件内容
 * @param string $attachment 附件列表
 * @return boolean 
 */
function think_send_mail($to, $name, $subject = '', $body = '111', $attachment = null) {
    $config = C('THINK_EMAIL');
    vendor('PHPMailer.class#phpmailer'); //从PHPMailer目录导class.phpmailer.php类文件
    $mail = new \PHPMailer();
    $mail->CharSet = 'UTF-8'; //设定邮件编码，默认ISO-8859-1，如果发中文此项必须设置，否则乱码
    $mail->IsSMTP();  // 设定使用SMTP服务
    $mail->SMTPDebug = 1;                     // 关闭SMTP调试功能
    // 1 = errors and messages
    // 2 = messages only
    $mail->SMTPAuth = true;                  // 启用 SMTP 验证功能
    $mail->SMTPSecure = 'ssl';                 // 使用安全协议
    $mail->Host = $config['SMTP_HOST'];  // SMTP 服务器
    $mail->Port = $config['SMTP_PORT'];  // SMTP服务器的端口号
    $mail->Username = $config['SMTP_USER'];  // SMTP服务器用户名
    $mail->Password = $config['SMTP_PASS'];  // SMTP服务器密码
    $mail->SetFrom($config['FROM_EMAIL'], $config['FROM_NAME']);
    $replyEmail = $config['REPLY_EMAIL'] ? $config['REPLY_EMAIL'] : $config['FROM_EMAIL'];
    $replyName = $config['REPLY_NAME'] ? $config['REPLY_NAME'] : $config['FROM_NAME'];
    $mail->AddReplyTo($replyEmail, $replyName);
    $mail->Subject = $subject;

    $mail->MsgHTML($body);
    $mail->AddAddress($to, $name);

    return $mail->Send() ? true : $mail->ErrorInfo;
}

function send($to) {
    //初始化必填
    $options['accountsid'] = '409c194f63fc342f1414a50c01639c3c'; //填写自己的
    $options['token'] = '4994964c66aecbe132f91bdb4fbc6d92'; //填写自己的
    //导入类库
    import("Org.Ucpaas");
    //初始化 $options必填
    $ucpass = new \Ucpaas($options);

    //随机生成6位验证码
    srand((double) microtime() * 1000000); //create a random number feed.
    $ychar = "0,1,2,3,4,5,6,7,8,9,A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z";
    $list = explode(",", $ychar);
    for ($i = 0; $i < 6; $i++) {
        $randnum = rand(0, 35); // 10+26;
        $authnum.=$list[$randnum];
    }

    //短信验证码（模板短信）,默认以65个汉字（同65个英文）为一条（可容纳字数受您应用名称占用字符影响），超过长度短信平台将会自动分割为多条发送。分割后的多条短信将按照具体占用条数计费。
    $appId = "1a7b68323f184132aa7727861750b43a";  //填写自己的
    $templateId = "24686";
    $param = $authnum;


    $arr = $ucpass->templateSMS($appId, $to, $templateId, $param);

    return $arr;
}
